/*
* 文件：SkipUnityLogoSettings.cs
* 作者：王阳
* 时间：2019-5-20
* 描述：免费版Unity强制跳过发布的程序的启动画面(UnityLogo)
*/
using System;
using UnityEditor;
using UnityEngine;

namespace UnityXEditor
{
    [Serializable]
    public class SkipUnityLogoSettings
    {
        public enum SkipUnityLogoDelay
        {
            立即跳过 = 0,
            延迟10毫秒 = 10,
            延迟20毫秒 = 20,
            延迟50毫秒 = 50,
            延迟100毫秒 = 100,
            延迟200毫秒 = 200,
            延迟500毫秒 = 500,
            延迟1000毫秒 = 1000,
            延迟2000毫秒 = 2000,
            延迟3000毫秒 = 3000,
        }
        [SerializeField]
        private bool m_EnabledSkipUnityLogo = false;
        [SerializeField]
        private SkipUnityLogoDelay m_SkipUnityLogoDelay = SkipUnityLogoDelay.立即跳过;
        public bool enabledSkipUnityLogo
        {
            get { return m_EnabledSkipUnityLogo; }
            set
            {
                if (value != m_EnabledSkipUnityLogo)
                {
                    m_EnabledSkipUnityLogo = value;
                    Update();
                }
            }
        }
        public void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            m_EnabledSkipUnityLogo = EditorGUILayout.Toggle("免费版Unity强制跳过发布的程序的启动画面(UnityLogo)", m_EnabledSkipUnityLogo);
            EditorGUI.BeginDisabledGroup(!m_EnabledSkipUnityLogo);
            m_SkipUnityLogoDelay = (SkipUnityLogoDelay)EditorGUILayout.EnumPopup(m_SkipUnityLogoDelay);
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
        }
        public void Update()
        {
            CodeFileTool.CommentsLine("SkipUnityLogo.cs", "#define ENABLED", m_EnabledSkipUnityLogo);
            if (m_EnabledSkipUnityLogo)
            {
                switch (m_SkipUnityLogoDelay)
                {
                    case SkipUnityLogoDelay.立即跳过:
                        CodeFileTool.CommentsLine("SkipUnityLogo.cs", "System.Threading.Thread.Sleep(", ";", false);
                        break;
                    default:
                        CodeFileTool.CommentsLine("SkipUnityLogo.cs", "System.Threading.Thread.Sleep(", ";", true);
                        CodeFileTool.ReplaceLine("SkipUnityLogo.cs", "System.Threading.Thread.Sleep(", ";", $"System.Threading.Thread.Sleep({(int)m_SkipUnityLogoDelay});");
                        break;
                }
            }
        }
    }
}